package com.yao.mall.controller;

import com.yao.mall.common.Result;
import com.yao.mall.model.dto.CarouselRequest;
import com.yao.mall.model.vo.CarouselVO;
import com.yao.mall.service.CarouselService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jiahua.yao
 * @version 1.0
 * @description 轮播图控制层
 * @date 2024/3/19 16:41
 */
@RestController
@RequestMapping("/carousel")
@Slf4j
@Tag(name = "轮播图相关接口")
public class CarouselController {
    @Resource
    private CarouselService carouselService;

    @GetMapping("/get")
    @Operation(summary = "获取所有轮播图")
    public Result<List<CarouselVO>> getCarousel(Integer site) {
        if(site == null){
            //如果没有传位置信息，默认显示首页的轮播图信息
            site = 0;
        }
        List<CarouselVO> carouselVOList = carouselService.getCarousel(site);
        return Result.success(carouselVOList);
    }

    @PostMapping("/add")
    @Operation(summary = "添加轮播图")
    public Result<Boolean> addCarousel(@RequestBody CarouselRequest carouselRequest) {
        Boolean aBoolean = carouselService.addCarousel(carouselRequest);
        return Result.success(aBoolean);
    }

    @PutMapping("/update")
    @Operation(summary = "修改轮播图")
    public Result<Boolean> updateCarousel(@RequestBody CarouselRequest carouselRequest) {
        Boolean aBoolean = carouselService.updateCarousel(carouselRequest);
        return Result.success(aBoolean);
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "删除轮播图")
    public Result<Boolean> deleteCarousel(@PathVariable Long id) {
        Boolean aBoolean = carouselService.deleteCarousel(id);
        return Result.success(aBoolean);
    }

}
